package cn.xorange.commons.system.service.platform.impl;

import cn.xorange.commons.core.basic.service.BaseService;
import cn.xorange.commons.core.exception.SysException;
import cn.xorange.commons.system.entity.platform.SysProduct;
import cn.xorange.commons.system.entity.platform.SysProductSpu;
import cn.xorange.commons.system.mapper.platform.SysProductMapper;
import cn.xorange.commons.system.mapper.platform.SysProductSpuMapper;
import cn.xorange.commons.system.service.platform.ISysProductSpuService;
import cn.xorange.commons.core.constants.SysConstants;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author : yangjian
 * date : 2024/9/13
 * description :
 */
@Service
public class SysProductSpuServiceImpl extends BaseService<SysProductSpu, SysProductSpuMapper>
        implements ISysProductSpuService {

    @Resource
    SysProductMapper productMapper;

    @Override
    public int checkSpuByDefaultProductId(Long productId) {
        return mapper.selectSpuByDefaultProductId(productId);
    }

    @Override
    public void checkProductBySpuId(Long spuId) {
        SysProduct product = new SysProduct();
        product.setProductSpu(spuId);
        product.setDelFlag(SysConstants.FLAG_SUCCESS);
        int num = productMapper.count(product);
        if(num>0){
            throw SysException.error("该规格存在在用功能,无法删除");
        }
    }

    @Override
    public int checkSpuByAgreementId(Long agreementId) {
        SysProductSpu spu = new SysProductSpu();
        spu.setAgreementId(agreementId);
        return mapper.count(spu);
    }

}
